home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Source / 10-InfoSystems / netscape_info / netscape-admin-i.frm.z / netscape-admin-i.frm
Encoding:
Text File  |  1997-07-30  |  4.7 KB  |  160 lines

  1. #!/usr/bin/perl5 -w
  2. #
  3. # netscape-admin-i.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: netscape-admin-i.frm,v 1.3 1997/06/19 22:26:09 shotes Exp $
  21.  
  22. #
  23. # Program to give onRamp access to the netscape admin
  24. # server "ns-admin" for configuring the netscape httpd server
  25. #
  26. # The program must 1) find if the server is installed, 2) find the port to use
  27. # to connect to the ns-admin server, 3) determine if it is running,
  28. # 4) start it if not,  5) redirect the url to the admin-server or 6) if it is
  29. # not installed and configured, to the url for the marketing blurb
  30. #
  31. # NOTE,  this script must be run as root if it must start up the server.
  32. ######################################################################
  33. # global variables                             #
  34. ######################################################################
  35. #
  36. # List of possible netscape server home directories.
  37. # Feel free to extend the list.
  38. #
  39. @ns_admin_home_dirs = (
  40.     '/usr/ns-home',
  41.     '/var/ns-home',
  42.     '/var/netscape',
  43.     '/var/www/ns-home', 
  44.     '/var/www/netscape', 
  45. );
  46.  
  47. $ns_admin_config_file = 'admserv/ns-admin.conf';  # below home_dir
  48.  
  49. $start_admin = 'start-admin';    # the command in homedir to start the server
  50.         
  51. $home_dir = "";            # global variable to save netscape home dir
  52.  
  53. $admin_port = -1;            # port of the netscape admin server
  54.  
  55. # get the hostname to construct the re-direct url's
  56. #
  57.  
  58. # this is not needed when we administer with "localhost:81"
  59. #
  60. #$hstname = `/usr/bsd/hostname`;
  61. #chop($hstname);            # remove the trailing '\n'
  62. #
  63. #$host_name = $hstname;
  64.  
  65. #######################################################################
  66. # First see if we can find the admin server.                  #
  67. #######################################################################
  68.  
  69. DIR:
  70. foreach $dir (@ns_admin_home_dirs) {
  71.    $file = $dir . "/". $ns_admin_config_file;
  72.    if (! open(FILE, $file)) {
  73. #    warn "Cannot open file $file: $!\n";
  74.         next;            # Not in this directory try the next
  75.    }
  76.    $home_dir = $dir;
  77.    
  78.    # Look through the file for the line defining the port the admin server uses
  79.    #
  80.    while (<FILE>) {
  81.     if (/^Port\s+([0-9]+)/) {
  82.         $admin_port = $1;
  83.         last DIR;        # found it get out of the loop
  84.     }
  85.    }
  86. }
  87.  
  88. # So was it installed? Check if there are any news directories under ns-home
  89. # XXX this assumes 1) news is under the same home as the admin-server for it.
  90. # 2) The netscape naming convention of news-<port> is followed.
  91. #
  92. $installed = 0;
  93. open(IN, "/bin/ls $home_dir |");
  94. while(<IN>) { if ($_ =~ m:http[d|s]-:) { $installed = 1; } }
  95. close(IN);
  96. if (! $installed) {
  97.     # nope, redirect to the marketing verbage by creating an html page
  98.     # with the marketing url
  99.     #
  100.     print "Content-type: text/html\n\n";
  101.     print <<EndOfPass;
  102.     <HTML>
  103.     <HEAD>
  104.     <TITLE>Netscape HTTPD</TITLE>
  105.     <META HTTP-EQUIV="refresh" CONTENT="0; URL=ns-httpd-marketing.cgi">
  106.     </HEAD>
  107.     <BODY></BODY>
  108.     </HTML>
  109. EndOfPass
  110.  
  111.     exit 0;
  112. }
  113. ####################################################################### 
  114. # Now let's see if it is already running                  #
  115. #######################################################################
  116. #
  117. # Make a pattern for the test in the if statement
  118. # This can be a problem if the server is started any way other than with its
  119. # full pathname. XXXX
  120. #
  121. $admin_process = $home_dir . "/admserv/ns-admin";
  122.  
  123. # search the ps output for the admin process.
  124. $start = 1;
  125. open(IN, "/bin/ps -ef |");
  126. while(<IN>) {
  127.     if ($_ =~ m:$admin_process:) { $start = 0; }
  128. }
  129. close(IN);
  130.  
  131. if ($start) {
  132.     # it wasn't running,  start it up.
  133.     #
  134.    system $home_dir . "/" . $start_admin;
  135. }
  136.  
  137. ######################################################################
  138. # re-direct to the admin server url                     #
  139. ######################################################################
  140. #
  141.  
  142. $url = "http://" . $ENV{'SERVER_NAME'} . ":" . $admin_port;
  143.  
  144. print "Window-target: gateway_ns-admin\n";
  145. print "Content-type: text/html\n\n";
  146. print <<EndOfPass;
  147.     <HTML>
  148.     <HEAD>
  149.     <TITLE>Netscape  HTTPD</TITLE>
  150.     <META HTTP-EQUIV="refresh" CONTENT="0; URL=$url">
  151.     </HEAD>
  152.     <BODY></BODY>
  153.     </HTML>
  154. EndOfPass
  155.  
  156. exit 0;
  157.